package net.interest.curation.model;

import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import org.slim3.datastore.Attribute;
import org.slim3.datastore.Datastore;
import org.slim3.datastore.Model;
import org.slim3.datastore.ModelRef;
import org.slim3.datastore.ModificationDate;

import com.google.appengine.api.datastore.Key;

@Model(schemaVersion = 1)
public class ScrapBook {

    @Attribute(primaryKey = true)
    private Key key;

    private ModelRef<User> userRef = new ModelRef<User>(User.class);

    @Attribute
    private String name;
    
    @Attribute(unindexed = true)
    private Set<Key> entrieKeys = new HashSet<Key>();
    
    @Attribute(listener = ModificationDate.class)
    private Date updatedAt;
    
    public Key getKey() {
        return key;
    }

    public void setKey(Key key) {
        this.key = key;
    }

    public ModelRef<User> getUserRef() {
        return userRef;
    }
    
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Set<Key> getEntrieKeys() {
        return entrieKeys;
    }
    public void setEntrieKeys(Set<Key> entries) {
        this.entrieKeys = entries;
    }

    public Collection<ScrapBookEntry> getEntries() {
        return Datastore.get(ScrapBookEntry.class, this.entrieKeys);
    }

    public Date getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(Date updatedAt) {
        this.updatedAt = updatedAt;
    }

}
